home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Testing & Debugging / Virtual User tools / SPEC S&L v.1.0.1 / Libraries / Geometry.lib < prev    next >
Encoding:
Text File  |  1993-12-17  |  7.8 KB  |  213 lines  |  [TEXT/MPS ]

  1. #
  2. # ****************************************************************************
  3. #
  4. #    File Name:        Geometry.lib
  5. #
  6. #    Contains:    xxx put contents here xxx
  7. #
  8. #    Written by:    Kevin Avoy, Ken Landreth, Michael Leong, Gil Spencer et al
  9. #
  10. #    Copyright:    © 1993 by Apple Computer, Inc., all rights reserved.
  11. #
  12. # ****************************************************************************
  13. #            C h a n g e        H i s t o r y (most recent first):
  14. # ****************************************************************************
  15. #
  16. #        Vers      Date        Author        Description
  17. #        ----    --------    ------    ---------------------------------------------
  18. #     <1.0.3>    12/13/93    KTA        Added task CenterPointOfRect()
  19. #        <1+>     5/21/93    NAGA        Adding header and porting old files to follow new standards
  20. #
  21. # ****************************************************************************
  22. #
  23.  
  24. #########################################################################
  25. #                        PtInRect(thePoint,theRect)
  26. #========================================================================
  27. # Author:            NJV
  28. # Description:        This routine determines whether or not thePoint 
  29. #                    is contained within theRect (including borders). 
  30. # Parameters:        thePoint - a list of two integers
  31. #                    theRect - holds the coordinates of the rectangle.
  32. # Returns:            true - point lies in the rectangle.
  33. #                    false - point does NOT lie in the rectangle.
  34. # Examples:            isIt := PtInRect(thePoint,theRect).
  35. # Assumptions:        None
  36. #========================================================================
  37. # History:
  38. #
  39. #########################################################################
  40. TASK PtInRect(thePoint,theRect) begin
  41.     return( ((thePoint[1] >= theRect[1]) and (thePoint[1] <= theRect[3]))
  42.             and ((thePoint[2] >= theRect[2]) and (thePoint[2] <= theRect[4])) );
  43. end;
  44.  
  45. ########################################################################
  46. #                        RndPtInWindow(specifier:=-1)
  47. #=======================================================================
  48. # Author:            Nick Vaccaro
  49. # Description:        Returns a random point inside of the window.  If specifier
  50. #                    is not passed, it will return a random point of the 
  51. #                    content region of the first window with a grow and a
  52. #                    zoom box, or if there are none, then the first window
  53. #                    it finds, and if no windows are present, returns 0.
  54. # Parameters:        specifier - title or ordinality of window
  55. # Returns:            0 - couldn't find window
  56. #                    Point -    list of 2 coordinates - {x,y}
  57. # Examples:            thePoint := RndPtInWindow();    # get random point in window content
  58. #                    thePoint := RndPtInWindow(1);    # random point in window ordinality 1
  59. #=======================================================================
  60. # History:
  61. #
  62. #########################################################################
  63. TASK RndPtInWindow(specifier:=-1) begin
  64.     if (specifier = -1)
  65.         return(RndPtInRect());    # return point in first window w/ size and zoom box
  66.     
  67.     if (TypeOf(specifier) = 'integer')
  68.         there := match [window o:specifier]!;
  69.     else
  70.         there := match [window t:specifier]!;
  71.         
  72.     if (there)
  73.         return(RndPtInRect(there.r));    # return random point in window's rect
  74.     else
  75.         return(0);
  76. end;
  77.  
  78. ########################################################################
  79. #                            RndPtInRect(theRect)
  80. #=======================================================================
  81. # Author:            Nick Vaccaro
  82. # Description:        Returns a random point inside of theRect.  If theRect
  83. #                    is not passed, it will return a random point of the 
  84. #                    content region of the first window with a grow and a
  85. #                    zoom box, or if there are none, then the first window
  86. #                    it finds, and if no windows are present, returns 0.
  87. # Parameters:        theRect - bounding rectangle
  88. # Returns:            0 - Default behavior requested with no windows up
  89. #                    Point -    list of 2 coordinates - {x,y}
  90. # Examples:            thePoint := RndPtInRect();    # get random point in window content
  91. #                    thePoint := RndPtInRect({20,20,80,80});    # random point in {20,20,80,80}
  92. # Assumptions:        None
  93. #=======================================================================
  94. # History:
  95. #
  96. #########################################################################
  97. TASK RndPtInRect(theRect:=-1) begin
  98.     if (theRect = -1) begin    # use content rect of first window with grow and zoom box
  99.         foo := match [window g:true z:true]!;
  100.         if (foo)
  101.             theRect := foo.r;
  102.         else begin
  103.             foo := match [window]!;        # try to find any window
  104.             if (not foo)
  105.                 return(0);
  106.             else
  107.                 theRect := foo.r;
  108.         end;
  109.     end;
  110.     x := Random(theRect[1],theRect[3]);
  111.     y := Random(theRect[2],theRect[4]);
  112.     return({x,y});
  113. end;
  114.  
  115. #########################################################################
  116. #                        RectInRect(rect1,rect2)
  117. #========================================================================
  118. # Author:            SMQ
  119. # Description:        This routine determines whether or not first rectangle 
  120. #                    lies completely within the second.  This is done by 
  121. #                    comparing the coordinates of both rectangles. 
  122. # Parameters:        rect1 - holds the coordinates of the first rectangle.
  123. #                    rect2 - holds the coordinates of the second rectangle.
  124. # Returns:            value - first rectangle lies in the second.
  125. #                    false - first rectangle does NOT lie in the second.
  126. # Examples:            RectInRect(rect1,rect2).
  127. # Assumptions:        None
  128. #========================================================================
  129. # History:
  130. #
  131. #########################################################################
  132. TASK RectInRect(rect1, rect2) begin
  133.  
  134.     Left1 := rect1[1];
  135.     Top1 := rect1[2];
  136.     Right1 := rect1[3];
  137.     Bottom1 := rect1[4];
  138.     
  139.     Left2 := rect2[1];
  140.     Top2 := rect2[2];
  141.     Right2 := rect2[3];
  142.     Bottom2 := rect2[4];
  143.     
  144.     return (((Left2 <= Left1) and (Top2 <= Top1) and (Right2 >= Right1) and (Bottom2 >= Bottom1)));
  145. end;
  146.  
  147.  
  148. ########################################################################
  149. #                        GetXYRandom(inset, Rect, numPts)
  150. #=======================================================================
  151. # Author:             SL
  152. # Description:        Returns a random X and Y coordinate in the specified
  153. #                    Rect.
  154. # Parameters:        inset - ltrb inset from scrn or window
  155. #                    specifier > 0 window to find coords in
  156. #                              = O coords in window with s:doc g:true and c:true
  157. #                              < 0 coords in specified screen.  Screen numbersta
  158. #                                is negative of specifier.
  159. # Returns:            xyRandom - List of random X and Y.  eg. { x, y }
  160. #=======================================================================
  161. ########################################################################
  162. TASK GetXYRandom(inset := { 0,0,0,0}, Rect := {}, numPts := 1) 
  163. begin        
  164.     pointlist := {};
  165.     if not (Rect) 
  166.         match[screen m:1 r:?Rect];
  167.     if (rect) 
  168.     begin
  169.         maxX := rect[3] - rect[1] - inset[3];
  170.         maxY := rect[4] - rect[2] - inset[4];
  171.         for i := 1 to numPts
  172.         begin
  173.             xRandom := random(inset[1], maxX);
  174.             yRandom := random(inset[2], maxY);
  175.             
  176.             thePoint := { xRandom, yRandom };
  177.             if(numPts > 1)        # Do we want a point list
  178.                 pointList := insert(thePoint , i, pointList );
  179.         end;
  180.         if(numPts = 1)    # If there is only one return it just like we always have
  181.             returnVal := thePoint;
  182.         else             # Otherwise return a list of points { {xPt,yPt},{xPt2, yPt2} };
  183.             returnVal := pointList;
  184.     end;
  185.     else
  186.         returnVal := 0;
  187.     return(returnVal);
  188. end; # getXYRandom()
  189.  
  190.  
  191. ########################################################################
  192. #                        CenterPointOfRect(pTheRect)
  193. #=======================================================================
  194. # Author:             Kevin Avoy
  195. # Description:        Returns the center point of the input parameter <pTheRect>
  196. # Parameters:        pTheRect - the rect that you want the center point of.
  197. # Returns:            returnVal  - List { x, y }
  198. #=======================================================================
  199. # History:
  200. # KTA    12/13/93    Created
  201. ########################################################################
  202. TASK CenterPointOfRect(pTheRect := {})
  203. begin
  204.     returnVal := 0;
  205.     if(pTheRect)
  206.     begin
  207.         x := ((pTheRect[3] + pTheRect[1])/2);
  208.         y := ((pTheRect[4] + pTheRect[2])/2);
  209.         
  210.         returnVal := {x,y};
  211.     end;
  212.     return(returnVal);
  213. end;